package com.tuanzi.loan.web.bean.application;

import com.google.common.collect.Lists;
import com.tuanzi.loan.business.entity.application.LoanApplicationExportGroupPage;
import com.tuanzi.loan.business.service.application.LoanApplicationExportGroupService;
import com.tuanzi.loan.business.service.application.LoanApplicationExportGroupPageService;
import com.tuanzi.loan.core.aspect.Debug;
import com.tuanzi.loan.vo.request.application.LoanApplicationExportGroupRequest;
import com.tuanzi.loan.vo.response.application.LoanApplicationExportGroupResponse;
import com.tuanzi.loan.web.configuration.JSFListingBean;
import com.tuanzi.loan.web.lazy.application.LoanApplicationExportGroupLazyDataModel;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.faces.bean.ViewScoped;
import java.util.List;

import static com.tuanzi.loan.business.constants.DictionaryCode.EXPORT_TYPE;

/**
 * @Auther: hequnayu
 * @Date: 2019/7/30 16:01
 * @Description:
 */
@Data
@Debug
@Component
@ViewScoped
@EqualsAndHashCode(callSuper = true)
public class LoanApplicationExportGroupListBean extends JSFListingBean<LoanApplicationExportGroupRequest,LoanApplicationExportGroupResponse> {

    private static final long serialVersionUID = -567662091234162413L;

    @Autowired
    private LoanApplicationExportGroupService groupService;
    @Autowired
    private LoanApplicationExportGroupPageService pageService;

    private List<LoanApplicationExportGroupPage> pageList;

    @PostConstruct
    private void init() {
        initLazyDataModel();
    }

    public void onReset() {
        initLazyDataModel();
    }

    public String onAdd() {
        return redirect("/views/application/group/info.xhtml");
    }

    public String onEdit(String id) {
        return redirect("/views/application/group/info.xhtml?id=" + id);
    }

    public void onDelete(Long id){
        groupService.delete(id);
    }

    private void initLazyDataModel() {
        $ = new LoanApplicationExportGroupRequest();
        pageList = pageService.findAll();
        lazyDataModel = new LoanApplicationExportGroupLazyDataModel($);
    }

    @Override
    protected List<String> getDictionaryCodes() {
        return Lists.newArrayList(EXPORT_TYPE);
    }
}
